<template>
	<HyCard title="机构抽取方式">
		<HyForm :hyFormDefault="hyFormDefault" :hyFormConfig="hyFormConfig" :hyFormFields="hyFormFields" ref="hyFormRef">
			<template #custom>
				<InstitutionTable :routerParams="props.routerParams" ref="institutionTableRef" />
			</template>
		</HyForm>
	</HyCard>
</template>
<script setup lang="ts">
import HyForm from '/@/components/HyForm/index.vue';
import HyCard from '/@/components/HyCard/index.vue';
import { useDict } from '/@/hooks/dict';
import InstitutionTable from '../InstitutionTable/index.vue';
// 定义字典
const { yes_no_type } = useDict('yes_no_type');
const props = defineProps({
	routerParams: {
		type: Object,
		default: () => {
			return {};
		},
	},
	detailData: {
		type: Object,
		default: () => {
			return {};
		},
	},
	institutionAvoidanceData: {
		type: Object,
		default: () => {
			return [];
		},
	},
});
const hyFormDefault = ref({});
watch(
	() => props.detailData,
	(nv1: any) => {
		hyFormDefault.value = nv1;
	},
	{ immediate: true }
);
watch(
	() => props.institutionAvoidanceData,
	(nv1: any) => {
		if (nv1 && nv1.length > 0) {
			nextTick(() => {
				institutionTableRef.value.tableData = nv1;
			});
		}
	},
	{ immediate: true }
);
//配置基本信息表单
const hyFormFields = computed(() => {
	return {
		institutionSecret: {
			label: '是否拥有涉密资质',
			type: 'select',
			required: true,
			options: yes_no_type.value,
			disbled: true,
		},
		institutionCount: {
			label: '邀请机构数',
			type: 'inputNumber',
			required: true,
		},
	};
});
const hyFormRef = ref();
//动态表单配置
const hyFormConfig = computed(() => {
	return {
		labelWidth: '150px',
		type: props.routerParams.operateType === 'add' ? 'submit' : 'view',
	};
});
const institutionTableRef = ref();
const check = async () => {
	const result = await hyFormRef.value.check();
	return result;
};
const getData = () => {
	return {
		...hyFormRef.value.hyForm,
		institutionAvoidanceList: institutionTableRef.value?.tableData || [],
	};
};
defineExpose({ check, getData });
</script>
<style scoped lang="scss"></style>
